package offer;

public class GetIntersectionNode_52 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {

        if(headA == null || headB == null) return null;

        ListNode l = headA;
        ListNode r = headB;
        while (l != r){
            l = l != null ? l.next : headB;
            r = r != null ? r.next : headA;
        }
        return l;



    }

  public class ListNode {
      int val;
      ListNode next;
      ListNode(int x) {
          val = x;
          next = null;
      }
  }
}
